import User.*;

import java.sql.SQLException;
import java.util.Scanner;

public class Main {
    public static void main (String[] args) throws SQLException {
        //通过login登陆
        User user=login();
        while (true){
            int choice=user.menu();
            user.doOperation(choice);
        }
    }
    private static User login(){
        Scanner scanner=new Scanner(System.in);
        System.out.println ("请输入用户名");
        String username=scanner.next();
        System.out.println ("请输入密码");
        String password=scanner.next();
        //2、从数据库根据用户名来查密码对不对
        UserDao userDao=new UserDao();
        User user=userDao.selectByName(username);
        if(user==null){
            //不存在
            System.out.println ("登陆失败，用户不存在");
            //退出程序
            System.exit (1);
        }
        if(!user.getPassword().equals(password)){
            //密码不对
            System.out.println ("登陆失败，密码不对");
            System.exit(1);
        }
        return user;
    }

}
